<template>
  <el-dialog
    title="分配角色"
    :visible="assignroledialog"
    width="30%"
    @close="guanbi"
  >
    <!-- ele的多选框需要绑定两个数组，一个数组是空的当选中时数据进去里面，一个用作v-for -->
    <el-checkbox-group v-model="cheaklist">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
    <el-button @click="btnOK">确定</el-button>
  </el-dialog>
</template>

<script>
import { getRoleInfo } from '@/api/setting.js'
import { getUserDetailById } from '@/api/user'
import { assignRole } from '@/api/employees'
export default {
  props: {
    assignroledialog: {
      type: Boolean,
      default: false
    },
    employeeId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      list: [],
      cheaklist: []
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    async  btnOK() {
      await assignRole({
        id: this.employeeId,
        roleIds: this.cheaklist
      })
      this.$message.success('修改成功')
      this.$emit('update:assignroledialog', false)
    },
    guanbi() {
      this.$emit('update:assignroledialog', false)
    },
    async getRoleList() {
      const { rows } = await getRoleInfo({ page: 1, pagesize: 100 })
      this.list = rows
    },
    async getUserDetail(id) {
      const res = await getUserDetailById(id)
      this.cheaklist = res.roleIds
    }
  }
}
</script>

<style>

</style>
